$(function () {

    var x_formForm = "#pricesForm";
    var x_formSelect = "#pricesForm select";
    var x_formHotelID = "#pricesForm #hotel_id";
    var x_formTrigger = "#pricesForm #nr_adults";
    var x_formMask = ".calculation";
    var resultsHTML = {
        'nr_adults': '#nr_adults',
        'nr_childrens': '#nr_childrens',
        'nr_babies': '#nr_babies',
        'check_in': '#check_in',
        'check_out': '#check_out',
        'service_persons': '.service_persons',
        'service_periods': '.service_periods',
        'service_total': '.service_total',
        'too_many': '.too_many'
    }

    var myCalculation = new API.x_calculation.CalculationManager(x_formForm, x_formSelect, x_formHotelID, x_formTrigger, x_formMask, resultsHTML, API.Data.lang);

    myCalculation.Initialize();

    var myItems = d;
    var isPreview = preview;  // is dates submit or not

    var myCalendar = new API.x_calendar.CalendarManager(myItems, API.Data.lang, isPreview, x_formTrigger);

    myCalendar.Initialize();

    $("#pricesForm .button.green").on('click', function () {     // glavno input dugme na strani detalji unutar forme

        if (myCalculation.Data.available === false) {
            alert(myCalculation.Data.message);
            return false;
        }

    });

    $(".button.green.centered").on('click', function () {     // glavno input dugme na strani detalji unutar forme

        if (myCalculation.Data.available === false) {

            $.scrollTo('#tabvanilla', 500);
            $("#tabvanilla").tabs("option", "active", 1);
        } else {
            $('#pricesForm').submit();
        }

        return false;

    });

    $("#do_reviews").on('click', function () {     //see all review dugme

        $("#tabvanilla").tabs("option", "active", 3);
        $('#top_side #rating_box').hide();
        $('#top_side .map_callout').show();


        return false;
    });

    $("#read_all_reviews").on('click', function () {
        $("#do_reviews").trigger('click');
    });

    $(".ui-tabs-anchor").on('click', function () {
        if ($(this).attr('href') === '#reviews') {
            $('#top_side #rating_box').hide();
            $('#top_side .map_callout').show();
        } else {
            $('#top_side #rating_box').show();
            $('#top_side .map_callout').hide();
        }
    });

});



